using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

using System.Windows;
using System.Windows.Ink;
using WozLib.UI.Ink.SketchObjects;

namespace WozLib.UI.Ink.SketchCommands
{
  public class ModifyObjectSketchCommand : SketchCommand
  {
    [XmlElement("PreviousTargetWozObjects")]
    public List<SketchObject> PreviousTargetWozObjects
    {
      get
      {
        return _PreviousTargetWozObjects;
      }
      set
      {
        _PreviousTargetWozObjects = new List<SketchObject>(value);
      }
    } private List<SketchObject> _PreviousTargetWozObjects;

    public ModifyObjectSketchCommand()
    {
    }

    public ModifyObjectSketchCommand(IEnumerable<SketchObject> nextWozObjects, IEnumerable<SketchObject> previousTargetWozObjects)
      : base(nextWozObjects)
    {
      _PreviousTargetWozObjects = new List<SketchObject>(previousTargetWozObjects);
    }

    public override void Redo()
    {
      if (this.TargetWozObjects != null)
      {
        foreach (SketchObject wozObject in this.TargetWozObjects)
        {
          ISketchObject iWozObject = wozObject.GetIWozObject(this.WozClientCommandReferences.WozObjectRegistry);
          if (iWozObject != null)
          {
            iWozObject.SetProperty(wozObject.WozProperties);
          }
        }
      }
    }

    public override void Undo()
    {
      if (this.PreviousTargetWozObjects != null)
      {
        foreach (SketchObject wozObject in this.PreviousTargetWozObjects)
        {
          ISketchObject iWozObject = wozObject.GetIWozObject(this.WozClientCommandReferences.WozObjectRegistry);
          if (iWozObject != null)
          {
            iWozObject.SetProperty(wozObject.WozProperties);
          }
        }
      }
    }
  }
}
